<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="format-detection" content="telephone=no">
    <title>3</title>
    <link rel="stylesheet" type="text/css" href="{$Think.config.RESOURCEURL}wx_assets/css/product.css?v=201408281">
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/alertMsg.js"></script>
    <script type='text/javascript' src='{$Think.config.RESOURCEURL}wx_assets/js/jquery-1.7.1.min.js'></script>
    <script type='text/javascript' src="{$Think.config.RESOURCEURL}wx_assets/js/base.js"></script>
    <style>
        /*
    三列 图片加大，有空白  --
    */
        .load-more {
            margin-left: auto;
            margin-right: auto;
            font-size: 15px;
            color: #3985FF !important;
            height: 23px;
            line-height: 23px;
            /*border: 1px solid #3e3e3e;*/
            display: block;
            width: 100%;
            text-align: center;
            background: #fff;
            padding:10px 0;
            /*background-color: #5d5554;*/
            /*background-image: -ms-linear-gradient(top, #5c5453 0%, #4b4443 100%);*/
            /*background-image: linear-gradient(top, #5c5453 0%, #4b4443 100%);*/
            /*background-image: -webkit-gradient(linear,0 0%,0% 100%,from(#5c5453),to(#4b4443));*/
        }
        .load-more:before{
            content: ' ';width: 8px;height: 8px;border-top: 1px solid #7d7d7d;
            border-left: 1px solid #7d7d7d;position:relative;display:inline-block;
            border-color:#3985FF;-webkit-transform: rotate(225deg);margin-right: 10px;margin-bottom: 3px;
        }
        #page_allMenu section article dl {
            width: 30%;  display: inline-block;  position: relative;  float: left;
            padding-left: 4px;
            height: 180px;  border: 1px solid #e7eaeb;
            margin-top: 1px;  padding-bottom: 2px;  margin-bottom: 0px;
            margin-left: 0px;
            margin-right: 1px;
        }
        #page_allMenu section article dl dt h3 {
            font-size: 14px;  margin-bottom: 1px;  margin-top: 1px;  height: 18px;  overflow: hidden;
        }
        #page_allMenu section article dl:first-of-type {
            border-top: 1px solid #fff;  margin-top: 1px;
        }
        #page_allMenu section article dl dd img {
            height: 80px;  width: 70px;
            display: block;  position: relative;
            border-radius: 3px;  cursor: pointer;
            left: 0px;  top: 0px;
            margin-bottom:2px;
        }
        #page_allMenu section article dl dd:nth-of-type(2) {
            margin-top: 3px;
            margin-bottom: 6px;
            text-align:right;
            margin-right: 10px;
        }
        #page_allMenu section article dl dd:nth-of-type(2) del{
            display:none;
        }
        #page_allMenu section article dl dd:nth-of-type(3) {
            display: none;
        }
        #page_allMenu section article dl dd:nth-of-type(4) {
            /*float: right;*/
            position: relative;
            margin-right:0px;
            margin-left: -10px;
            display:block;
            text-align: right;
        }
        #page_allMenu section article dl .btn {
            position: relative;
            display: block;
            top: 0px;
            right: 0px;
            background-color: transparent;
            cursor: pointer;
            padding: 0px;  height: 38px;
            margin-top: -10px;
        }
        #page_allMenu section article{
            padding: 0 0px 0px;
        }

        /*over
        */
    </style>
</head>
<body id="page_allMenu">
<div class="center">
    <nav id="navBar" style="height: 356px;">
        <dl>
            <!--dt>分类</dt-->
            <volist name="tags" id="tag">
                <eq name="key" value="0">
                    <dd tagid={$tag.id} tagnum="{$tag.count}" class="active" >{$tag.name}
                        <if condition="$tag.reserveCount gt 0">
                            <span style="display: block;">{$tag.reserveCount}</span>
                            <else /><span style="display: none;"></span>
                        </if>
                    </dd>
                </eq>
                <neq name="key" value="0">
                    <dd tagid={$tag.id} tagnum="{$tag.count}">{$tag.name}
                        <if condition="$tag.reserveCount gt 0">
                            <span style="display: block;">{$tag.reserveCount}</span>
                            <else /><span style="display: none;"></span>
                        </if>
                    </dd>
                </neq>
            </volist>
        </dl>
    </nav>

    <section id="infoSection" style="height: 356px;padding-bottom: 60px; ">
        <article style="overflow-y: scroll;overflow-y:hidden;overflow-x:hidden "> <!--div class="h2">推荐菜</div-->
            <div id="pInfo" style="overflow: hidden">
                <volist name="products.productList" id="product">
                    <php>if($i <= 9){</php>
                    <dl id='{$product.id}' class="unchoose" dunitname="{$product.unitName}" dsubcount="2203"
                        dishid='{$product.id}' dname="{$product.name}" dtaste="" ddescribe="" data-inventory="{$product.inventory}" data-inventoryCount="{$product.inventoryCount}"
                        dprice="{$product.fixedPrice}" dishot="2" ddiscountedprice="{$product.discountedPrice}" disspecial="1" shopinfo="">
                        <dt>
                        <h3 onclick="onDetail({$product.id})" style="overflow : hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;width:100%;height:40px;white-space: inherit;word-break: break-word;">{$product.name}</h3>
                        </dt>
                        <dd>
                            <a href="javascript:void(0)" class="dataIn">
                                <img src='{$product.picUrl}' alt="" title="" onclick="onDetail({$product.id})">
                                <!-- <span></span> -->
                            </a>
                        </dd>
                        <empty name="product.picUrl">
                            <script>
                                $('#{$product.id}').css('paddingLeft', '5px');
                            </script>
                        </empty>
                        <dd>
                            <notempty name="product.fixedPrice">
                                <empty name="product.discountedPrice">
                                    <empty name="product.unitName">
                                        <em> {$product.fixedPrice}元 </em>
                                    </empty>
                                    <notempty name="product.unitName">
                                        <em> {$product.fixedPrice}元/{$product.unitName} </em>
                                    </notempty>
                                </empty>
                                <notempty name="product.discountedPrice">
                                    <empty name="product.unitName">
                                        <em> {$product.discountedPrice}元
                                            <del>{$product.fixedPrice}元 </del>
                                        </em>
                                    </empty>
                                    <notempty name="product.unitName">
                                        <em> {$product.discountedPrice}元/{$product.unitName}
                                            <del> {$product.fixedPrice}元/{$product.unitName} </del>
                                        </em>
                                    </notempty>
                                </notempty>
                            </notempty>
                        </dd>

                        <dd class="dpNum">{$product.salesCount}人点过</dd>
                        <if condition="($showBtn eq 1)">
                            <dd class="btn">
                                <button class="minus" style="display: inline-block; "><strong></strong></button>
                                <i style="display: inline-block; ">{$product.count}</i>
                                <button class="add"><strong></strong></button>
                            </dd>
                        </if>
                    </dl>
                    <php>}</php>
                </volist>
            </div>
            <php> if( 9<$products['total']){</php>
            <div class="jx_map" style="width:100%;padding:10px 0;">
                <a class="load-more" href="javascript:void(0);" onclick="loadmore(this);" data-start = "9" data-total="{$products['total']}" style="color:#000000">点击加载更多</a>
            </div>
            <php>}</php>
        </article> </section>

    <if condition="($showBtn eq 1)">
        <footer class="footFix">
            <button class="btn_change" id="btn_menu" onclick="return doMenu()">
                购物车
                <!--<span class="num">4</span> -->
            </button>
        </footer>
    </if>
</div>

<script>

    var hrefParamsArray = GetSessionIdFromHref(window.location.search);
    hrefParamsArray["userName"]='{$userName}';
    function GetSessionIdFromHref(search){
    　　	var args = search.substring(1);
	　　	var retval = new Array();
        args = args.split("&");
        for(var i = 0; i < args.length; i ++){
            str = args[i];
            var arg = str.split("=");
            if(arg.length <= 1) continue;

            if(arg[0] == 'params') {
                var params = decodeURIComponent(arg[1]);
                var obj = eval('(' + params + ')');
                retval["mid"] = obj.id;
            } else if(arg[0] == 'customerId') {
                retval["customerId"] = arg[1];
            }else if(arg[0] == 'userName'){
                retval["userName"] = arg[1];
            }
        }

        if (retval["userName"] == '') {
            retval["userName"] = '{$userName}';
        }
        return retval;
    }

    function setHeight(){
        var cHeight;
        cHeight = document.documentElement.clientHeight;
        cHeight = cHeight +"px"
        document.getElementById("navBar").style.height =  cHeight;
        document.getElementById("infoSection").style.height =  cHeight;
    }
    function onDetail(id) {
        var rootid = '';
        if (hrefParamsArray["rootid"] !== undefined) {
            rootid = ',"rootid":' + hrefParamsArray["rootid"];
        }
        window.location.href = 'call.html?userName=' + hrefParamsArray['userName'] + '&customerId='
        + hrefParamsArray['customerId'] + '&module=product&method=getProduct&params={"tplid":4,"id":"' + id + rootid + '"}';
    }
    //ajax处理
    function doSelect(){
        var dds = _qAll('#navBar dd');
        var aa=0, bb;
        var article = _q("#infoSection article");
        for (aa;aa<dds.length;aa++){
            dds[aa].onclick = function(){
                _q('.active').className = null;
                this.className = "active";

                var div =  document.getElementById("pInfo");
                div.innerHTML = '';
                var params;
                if ('{$groupBy}' == 'category') {
                    params = {
                        'module': 'product',
                        'method' : 'getProductListByCategory',
                        'params' : '{"cid":' +  this.getAttribute('tagid') + ',"counts":' +  9 + ',"tplid":"5"}'
                    };
                } else {
                    params = {
                        'module': 'product',
                        'method' : 'getProductByTagId',
                        'params' : '{"sid":-1,"tagId":' +  this.getAttribute('tagid') +
                        ',"counts":' + 9 + ',"cids":"","type":"buy","tplid":"5"}'
                    };
                }

                var urlString = 'call.json?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
                $.ajax({url : urlString,
                    dataType : "json",
                    type : "post",
                    data : params,
                    success : function(data) {
                        if (data.code != undefined) {
                            alert(data.msg);
                        }
                        var dishList = data.list;
                        var tagId = data['tagId'];

                        var str = '';
                        for(key in dishList) {
                            var temp = dishList[key].productList;
                            for(var i in temp){
                                var dish = temp[i];

                                if (dish['fixedPrice'] != 0 && dish['fixedPrice'] != null) {
                                    if (dish['discountedPrice'] == 0 || dish['discountedPrice'] == null) {
                                        if (!dish.unitName || dish.unitName == '') {
                                            var priceHtml = "<em>"+dish['fixedPrice']+"元</em>";
                                        } else {
                                            var priceHtml = "<em>"+dish['fixedPrice']+"元/" + dish["unitName"] + "</em>";
                                        }
                                    } else  {
                                        if (!dish.unitName || dish.unitName == '') {
                                            var priceHtml = "<em>"+dish['discountedPrice']+"元<del>"+dish['fixedPrice']+"元</del></em>";
                                        } else {
                                            var priceHtml = "<em>"+dish['discountedPrice']+"元/" + dish["unitName"] + "<del>"+dish['fixedPrice']+"元/" + dish["unitName"] + "</del></em>";
                                        }
                                    }
                                } else {
                                    var priceHtml = '';
                                }
                                var hotHtml = '';
                                var dSubCountHtml = '';
                                /*
                                 if (dish.dIsHot == view_const_dish_HOT_YES) {
                                 var hotHtml = '<span></span>';
                                 } else {
                                 var hotHtml = '';
                                 }
                                 */
                                if (dish['salesCount']) {
                                    var dSubCountHtml = dish['salesCount'] + '人点过';
                                } else {
                                    var dSubCountHtml = '';
                                }
                                var attrList = " id='" + dish['id'] + "' dUnitName='"+dish['unitName']+"' dSubCount='"+dish['dSubCount']+"' dishid='"+dish['id']
                                        +"' dname='"+dish['name']+"' dTaste='"+dish['dTaste']+"' dPrice='"+dish['fixedPrice']
                                        +"' dIsHot='"+dish['dIsHot']+"' ddiscountedprice='"+dish['discountedPrice']+"' dIsSpecial='"+dish['dIsSpecial']+"' data-inventory='"+dish['inventory']+"' data-inventoryCount='"+dish['inventoryCount']+"' ";

                                if (dish['picUrl'] == '') {
                                    attrList += " style='padding-left:5px;' ";
                                }

                                var imgStr = "<img src='"+dish.picUrl+"' alt='' title='' onclick=\"onDetail(\'"+dish.id+"\')\"/>";

                                //str += "<dl shopInfo='"+dish['allShopInfo']+"' "+attrList+"'><dt><h3>"+dish['name']
                                str += "<dl shopInfo=''"+attrList+"' data-inventory='"+dish['inventory']+"' data-inventoryCount='"+dish['inventoryCount']+"'><dt><h3 onclick=\"onDetail(\'"+dish.id+"\')\" style='word-wrap: break-word;width:100%;height:60px;overflow:hidden'>"+dish['name']
                                +"</h3></dt><dd><a href='javascript:void(0)' class='dataIn'> <img src='"+dish.picUrl+"' alt='' title='' onclick=\"onDetail(\'"+dish.id+"\')\"/>"
                                +hotHtml+"</a></dd><dd>"+priceHtml+"</dd><dd class='dpNum'>"+dSubCountHtml
                                +"</dd>";
                                if ({$showBtn} == 1){
                                    str += "<dd class='btn'><button class='minus'><strong></strong></button><i style='display: inline-block;'>"+dish['count']+"</i><button class='add'><strong></strong></button></dd>";
                                }
                                str += "</dl>";
                            }
                        }
                        if(data['list'][0].total>9){
                            var loadstr='<div class="jx_map" style="width:100%;padding:10px 0">\
									<a class="load-more" href="javascript:void(0);" onclick="loadmore(this)" data-start = "'+temp.length+'" data-total="'+data['list'][0].total+'" style="color:#000000">点击加载更多</a>\
									</div>';
                            if($(".load-more").length!=0){
                                $(".load-more").parent().remove();
                            }
                            $("#pInfo").parent().append(loadstr);

                        }else{
                            if($(".load-more").length!=0){
                                $(".load-more").parent().remove();
                            }
                        }
                        if (_q('.active').getAttribute('tagid') == tagId) {
                            div.innerHTML = str;
                            _q('#infoSection').scrollTop = 0;

                            var type = '{$type}';
                            if ({$showBtn} == 1) {
                                doSelectBtn();
                            }
                        }
                    },
                    error : function() {
                    }
                });
            }
        };
    }

    _forEach = function(arr, callback) {
        if (typeof arr === 'string'){
            try{arr = _qAll(arr);}
            catch(ex){console.log(ex);return;}
        }
        Array.prototype.forEach.call(arr, callback);
    };
    function loadmore(obj){
        var dd = $("#navBar dd.active");
        var me = $(obj);
        var LIMIT = 9;
        var total = me.data("total");
        var start = me.data("start");
        var p =  '{"sid":-1,"tagId":' +  dd.attr('tagid') +
                ',"counts":'+(total-start)+ ',"cids":"","type":"buy","tplid":"4","start":'+start+',"limit":'+(total-start)+'}';
        var params = {
            'module': 'product',
            'method' : 'getProductByTagId',
            'params' : p
        };
        var urlString = 'call.json?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
        $.ajax({url : urlString,
            dataType : "json",
            type : "post",
            data : params,
            success : function(data) {
                if (data.code != undefined) {
                    alert(data.msg);
                }
                var dishList = data.list;
                var tagId = data['tagId'];

                var str = '';
                for(var key in dishList) {
                    var temp = dishList[key].productList;
                    if(temp.length<=9){$(".jx_map").hide();}
                    else{me.data("start",(start+LIMIT));}
                    for(var i in temp) {
                        var dish = temp[i];
                        if (i < LIMIT) {
                            if (dish['fixedPrice'] != 0 && dish['fixedPrice'] != null) {
                                if (dish['discountedPrice'] == 0 || dish['discountedPrice'] == null) {
                                    if (!dish.unitName || dish.unitName == '') {
                                        var priceHtml = "<em>" + dish['fixedPrice'] + "元</em>";
                                    } else {
                                        var priceHtml = "<em>" + dish['fixedPrice'] + "元/" + dish["unitName"] + "</em>";
                                    }
                                } else {
                                    if (!dish.unitName || dish.unitName == '') {
                                        var priceHtml = "<em>" + dish['discountedPrice'] + "元<del>" + dish['fixedPrice'] + "元</del></em>";
                                    } else {
                                        var priceHtml = "<em>" + dish['discountedPrice'] + "元/" + dish["unitName"] + "<del>" + dish['fixedPrice'] + "元/" + dish["unitName"] + "</del></em>";
                                    }
                                }
                            } else {
                                var priceHtml = '';
                            }
                            var hotHtml = '';
                            var dSubCountHtml = '';
                            /*
                             if (dish.dIsHot == view_const_dish_HOT_YES) {
                             var hotHtml = '<span></span>';
                             } else {
                             var hotHtml = '';
                             }
                             */
                            if (dish['salesCount']) {
                                var dSubCountHtml = dish['salesCount'] + '人点过';
                            } else {
                                var dSubCountHtml = '';
                            }
                            var attrList = " id='" + dish['id'] + "' dUnitName='" + dish['unitName'] + "' dSubCount='" + dish['dSubCount'] + "' dishid='" + dish['id']
                                    + "' dname='" + dish['name'] + "' dTaste='" + dish['dTaste'] + "' dPrice='" + dish['fixedPrice']
                                    + "' dIsHot='" + dish['dIsHot'] + "' ddiscountedprice='" + dish['discountedPrice'] + "' dIsSpecial='" + dish['dIsSpecial'] + "' data-inventory='"+dish['inventory']+"' data-inventoryCount='"+dish['inventoryCount']+"' ";

                            if (dish['picUrl'] == '') {
                                attrList += " style='padding-left:5px;' ";
                            }
                            var inventory = dish['inventory'];
                            var inventoryCount = dish['inventoryCount'];
//                             data-inventory="{$product.inventory}" data-inventoryCount="{$product.inventoryCount}"
                            //str += "<dl shopInfo='"+dish['allShopInfo']+"' "+attrList+"'><dt><h3>"+dish['name']
                            str += "<dl shopInfo='" + attrList + "' data-inventory='"+inventory+"' data-inventory='"+inventoryCount+"'><dt><h3 onclick='onDetail('" + dish['id'] + "')' style='word-wrap: break-word;width:100%;height:60px;overflow:hidden'>" + dish['name']
                            + "</h3></dt><dd><a href='javascript:void(0)' class='dataIn'><img src='" + dish['picUrl'] + "' alt='' title='' onclick='onDetail('" + dish['id'] + "')' />"
                            + hotHtml + "</a></dd><dd>" + priceHtml + "</dd><dd class='dpNum'>" + dSubCountHtml
                            + "</dd>";
                            if ({$showBtn} == 1) {
                                str += "<dd class='btn'><button class='minus'><strong></strong></button><i style='display: inline-block;'>" + dish['count'] + "</i><button class='add'><strong></strong></button></dd>";
                            }
                            str += "</dl>";
                        }
                    }
                }
                $("#pInfo").append(str);


                doSelectBtn();

            },
            error : function() {
            }
        });
    }
    function countDish(){
        var total = 0,countdish;
        var dishNum = _qAll("#page_allMenu section article dl .btn i");
        _forEach(dishNum,function(ele,idx,dishNum){
            countdish = parseInt(ele.innerHTML);
            if(countdish>0){
                total++;
            }
        });

        if(total != 0){
            _q("#page_allMenu nav dl dd.active span").innerHTML = total;
            _q("#page_allMenu nav dl dd.active span").style.display='block';
        }else{
            _q("#page_allMenu nav dl dd.active span").style.display='none';
        }
    }

    function btnShowHide(num,btns){
        countDish();
        if (num <= 0) {
            btns.children[0].style.display ="none";
            btns.children[1].style.display ="none";
        }else{
            btns.children[0].style.display ="inline-block";
            btns.children[1].style.display ="inline-block";
        };
    }

    //选择菜品按钮样式
    $(".add").live("click",function(){
        var originalNum,countNumText;
        var inventory = $(this).parent().parent().data("inventory");
        var inventoryCount = $(this).parent().parent().data("inventorycount");
        var _self = this;
        var dishid = _self.parentNode.parentNode.getAttribute('dishid');
        originalNum = parseInt(_self.parentNode.children[1].innerHTML, 10);
        countNumText =  originalNum +1;
        if(inventory==1&&countNumText>inventoryCount){
            alert("超出库存数量");
            return;
        }
        var shopInfo =_self.parentNode.parentNode.getAttribute('shopInfo');
        _self.parentNode.children[1].innerHTML = countNumText;
        btnShowHide(countNumText,_self.parentNode);
        ajaxDishReset(dishid, countNumText, function(){}, function() {});
    });
    $(".minus").live("click",function(){
        var originalNum,countNumText;
        var _self = this;
        var dishid = _self.parentNode.parentNode.getAttribute('dishid');
        originalNum = parseInt(_self.parentNode.children[1].innerHTML, 10);
        countNumText =  originalNum -1;
        if(originalNum>0){
            var shopInfo =_self.parentNode.parentNode.getAttribute('shopInfo');
            _self.parentNode.children[1].innerHTML = countNumText;
            btnShowHide(countNumText,_self.parentNode);
            ajaxDishReset(dishid, countNumText, function(){}, function() {});
        }else if(originalNum<=0){
            countNumText=0;
            _self.parentNode.children[1].innerHTML = countNumText;
            btnShowHide(countNumText,_self.parentNode);
            ajaxDishRemove(dishid, function(){}, function() {});
        }
    });
    function doSelectBtn() {
        var btn = _qAll("article dl .btn");
        var btnIndex = 0,btnLength = btn.length;
        countDish();
        for(btnIndex;btnIndex<btnLength;btnIndex++){
            var countNumText=parseInt(btn[btnIndex].children[1].innerHTML),
                    btnAdd=btn[btnIndex].children[2],
                    btnMin=btn[btnIndex].children[0];

            btnShowHide(countNumText,btn[btnIndex]);
        } // for

    } // doSelectBtn
        function ajaxDishReset(dishid, count, successCallback, errorCallback) {
            var urlString = 'call.json?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
            $.ajax({url : urlString,
                dataType : "json",
                type : "post",
                data : {
                    'module': 'product',
                    'method' : 'updateOrderDetail',
                    'params' : '{"sid":-1,"pid":' + dishid +  ',"count":' + count + ',"type":"buy"}',
                },
                success : function(data) {
                    if (data['code'] != 0) {
                        errorCallback();
                        alert(data['msg']);
                        return;
                    } else {
                        successCallback();
                    }
                }
            });
        } // ajaxDishReset

        function ajaxDishRemove(dishid, successCallback, errorCallback) {
            var urlString = 'call.json?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
            $.ajax({url : urlString,
                dataType : "json",
                type : "post",
                data : {
                    'module': 'product',
                    'method' : 'removeOrderDetail',
                    'params' : '{"sid":-1,"pid":' + dishid + ',"type":"buy"}',
                },
                success : function(data) {
                    if (data['code'] != 0) {
                        alert(data['msg']);
                        errorCallback();
                        return;
                    } else {
                        successCallback();
                    }
                }
            });
        } // ajaxDishRemove


    function clearShow(){
        var all = _qAll(".showDetail"),ff = 0;
        for(ff;ff<all.length;ff++){
            _removeClass(all[ff],"sh");
            all[ff].parentNode.parentNode.style.zIndex = '0';
        }
    }

    function doMenu() {
        var params = '{"sid":-1,"type":"buy","tplid":4,"mid":' + hrefParamsArray["mid"] + '}';
        location.href = 'call.html?userName=' + hrefParamsArray['userName'] + '&customerId='
        + hrefParamsArray['customerId'] + '&module=product&method=getCart&params=' + params;
    }

    window.onload = function(){
        setHeight();
        doSelect();
        if ({$showBtn} == 1) {
            doSelectBtn();
        }
    }
    window.onresize = function(){setHeight();}

</script>

<script type="text/javascript">
    function resetAndAppendHerf(search){
    　　	var args = search.substring(1);
　　	var retval = new Array();
        args = args.split("&");
        for(var i = 0; i < args.length; i ++){
            str = args[i];
            var arg = str.split("=");
            if(arg.length <= 1) continue;
            if(arg[0] == 'userName'){
                args[i] = "userName=";
            }
        }
        return args.join("&");
    }

    $(function(){
        var imageUrl = '{$products.productList[0].picUrl}';
        var title = '{$products.productList[0].name}';
        var des = '点击这里查看商品';
        var search = '?' + resetAndAppendHerf(window.location.search);
        var shareUrlString = window.location.protocol + "//"
                + window.location.host + window.location.pathname + search;

        window.shareData = {
            "imgUrl": imageUrl,
            "timeLineLink":  shareUrlString ,
            "sendFriendLink":  shareUrlString ,
            "weiboLink":  shareUrlString ,
            "tTitle": title,
            "tContent": des,
            "fTitle": title,
            "fContent": des,
            "wContent": des
        };
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            // 发送给好友
            WeixinJSBridge.on('menu:share:appmessage', function (argv) {
                WeixinJSBridge.invoke('sendAppMessage', {
                    "img_url":  window.shareData.imgUrl,
                    "img_width": "640",
                    "img_height": "640",
                    "link": window.shareData.sendFriendLink,
                    "desc": window.shareData.fContent,
                    "title": window.shareData.fTitle
                }, function (res) {
                    _report('send_msg', res.err_msg);
                })
            });

            // 分享到朋友圈
            WeixinJSBridge.on('menu:share:timeline', function (argv) {
                WeixinJSBridge.invoke('shareTimeline', {
                    "img_url": window.shareData.imgUrl,
                    "img_width": "640",
                    "img_height": "640",
                    "link": window.shareData.timeLineLink,
                    "desc": window.shareData.tContent,
                    "title": window.shareData.tTitle
                }, function (res) {
                    _report('timeline', res.err_msg);
                });
            });

            // 分享到微博
            WeixinJSBridge.on('menu:share:weibo', function (argv) {
                WeixinJSBridge.invoke('shareWeibo', {
                    "content": window.shareData.wContent,
                    "url": window.shareData.weiboLink
                }, function (res) {
                    _report('weibo', res.err_msg);
                });
            });
        });
    });
</script>
</body>
</html>